home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / basic / mildred / lha / dispdemo.lha / DisplayDemo.asc next >
Text File  |  1999-03-01  |  8KB  |  92 lines

  1. ; DisplayDemo by Andreas Hakansson - AKA TJoMMe
  2. ; Shows how to setup a split screen display using
  3. ; Mildred. This could be used in a game with a
  4. ; two player mode.
  5. ;
  6. ; Original code by Mikkel lokke, but I have changed
  7. ; it a lot and adapted it for my use. Feel free to
  8. ; use it in your own programs.
  9.  
  10.  
  11. WBStartup                                                                                 ; Dont foget if you make an exe
  12. NoCli                                                                                     ; We dont need the CLI window
  13.  
  14. DEFTYPE.l                                                                                 ; Set default type to long
  15.  
  16. NEWTYPE.Data                                                                              ; Setup an array that stores
  17.  Xpos.w                                                                                   ; some information about the
  18.  Ypos.w                                                                                   ; displays. Needed when we scroll
  19.  XVelo.b                                                                                  ; more then one display. Could
  20.  YVelo.b                                                                                  ; proberbly be done some other way
  21. End NEWTYPE                                                                               ; but this is tidy
  22.  
  23. MCPU MProcessor                                                                           ; Tell mildred which cpu we have
  24. Mc2pCPUmode MProcessor                                                                    ; Tell mildred which c2p mode to use
  25.  
  26. MReserveBitmaps 1                                                                         ; We need one chunky bitmap
  27. MReservec2pWindows 1                                                                      ; We need one c2p window
  28.  
  29. MBitmap 0,640,512                                                                         ; Setup a chunky bitmap
  30.  
  31. *pbb.l=AllocMem(640*512,#MEMF_PUBLIC)                                                     ; Grab som mem for chunky bitmap
  32. If *pbb                                                                                   ; Check if we got it
  33.   CludgeBitMap 0,640,512,8,*pbb                                                           ; Create a planar bitmap
  34.   LoadBitMap 0,"M2P.ILBM",0                                                               ; Load in our picture
  35.   MPlanar16ToBitmap 0,*pbb                                                                ; Copy it to our chunky bitmap
  36.   Free BitMap 0                                                                           ; Get ride of planar bitmap
  37.   FreeMem *pbb,640*512                                                                    ; Get ride of allocated mem
  38. Else End                                                                                  ; Quit if we didnt get the memory
  39. EndIf                                                                                     ;
  40.  
  41. Mc2pWindow 0,320,128,640,320,256                                                          ;
  42.  
  43. Dim bmppnt.l(1)                                                                           ; Planar bitmap pointer array
  44. For n=0 To 1                                                                              ; Setup loop to create two bitmaps
  45.   bmppnt(n)=AllocMem(320*256,#MEMF_CHIP)                                                  ; Get some memory
  46.   If bmppnt(n)                                                                            ; Check if we got it
  47.     CludgeBitMap n,320,256,8,bmppnt(n)                                                    ; Create a bitmap with it
  48.   Else End                                                                                ; Quit if we didnt get the memory
  49.   EndIf                                                                                   ;
  50. Next                                                                                      ;
  51.  
  52. Dim scrtaglst.TagItem(7)                                                                  ; Setup a screen tag list
  53. scrtaglst(0)\ti_Tag = #SA_Left,0                                                          ; And fill it up
  54. scrtaglst(1)\ti_Tag = #SA_Depth,8                                                         ;
  55. scrtaglst(2)\ti_Tag = #SA_Width,320                                                       ;
  56. scrtaglst(3)\ti_Tag = #SA_Height,256                                                      ;
  57. scrtaglst(4)\ti_Tag = #SA_BitMap,Addr BitMap(0)                                           ;
  58. scrtaglst(5)\ti_Tag = #SA_ShowTitle,0                                                     ;
  59. scrtaglst(6)\ti_Tag = #SA_Draggable,0                                                     ;
  60. scrtaglst(7)\ti_Tag = #TAG_END                                                            ; Dont forget this one
  61.  
  62. ScreenTags 0,"DisplayDEMO",&scrtaglst(0)                                                  ; Open our screen
  63. ShowPalette 0                                                                             ; Show our palette
  64.  
  65. Dim View.Data(1)                                                                          ; Create an array to old display info
  66. For n=0 To 1                                                                              ; Setup loop to handle both displays
  67.   View(n)\Xpos = Rnd(317)+1                                                               ; Random a horizontal start coord
  68.   View(n)\Ypos = Rnd(381)+1                                                               ; Random a vertical start coord
  69.   View(n)\XVelo = 1                                                                       ; Set horizontal scroll speed
  70.   View(n)\YVelo = 1                                                                       ; Set vertical scroll speed
  71. Next                                                                                      ;
  72.  
  73. Repeat                                                                                    ; Setup our main loop
  74.   VWait                                                                                   ; Wait for the next vbl
  75.  
  76.   For n=0 To 1                                                                            ; Setup a loop to for both displays
  77.     Mc2p 0,MBitmapPtr(View(n)\Xpos,View(n)\Ypos,0),MGenericPtr(0,(n*128),bmppnt(dbuf),40) ; Copy chunky chunky to planar and
  78.                                                                                           ; place it correctly on screen
  79.  
  80.     View(n)\Xpos + View(n)\XVelo                                                          ; Calculate next x position
  81.     View(n)\Ypos + View(n)\YVelo                                                          ; Calculate next y position
  82.     If View(n)\Xpos=319 OR View(n)\Xpos=1 Then View(n)\XVelo=-View(n)\XVelo               ; Bounce if we've hit the edge
  83.     If View(n)\Ypos=383 OR View(n)\Ypos=1 Then View(n)\YVelo=-View(n)\YVelo               ; Bounce if we've hit the edge
  84.   Next                                                                                    ;
  85.  
  86.   ShowBitMap(dbuf)                                                                        ; Show the hidden buffer
  87.   dbuf=1-dbuf                                                                             ; Double buffer (0..1..0..1..)
  88.  
  89. Until RawStatus($45)                                                                      ; If ESC is pressed then quit
  90. End                                                                                       ; End our program
  91.  
  92.